function strToObj(jsonStr){
    var obj = JSON.parse(jsonStr)
    return obj
}

function objToStr(obj){
    var str = JSON.stringify(obj)
    return str
}


function getArray(jsonString,field){
     var jsObject = JSON.parse(jsonString)
        for ( var key in jsObject ) {
             if(key === field){
                return jsObject[key]
             }
     }
}

function getValue(jsonArrayObj,index,query){
    return jsonArrayObj[index][query]
}

function getKeyList(obj){
     var arr=[];
     for (var k in obj){
            arr.push(k)
     }
     return arr
}

//1.修改数组对象的值
function  midifyArrayValue(target,index,key,value){
    target[index][key] = value
}


//2.修改对象中的值
function setJsonObjectValue(obj,index,value){
    obj[index] = value
    return obj
}

//将对象写入到json对象
function saveDataToObj(target,data){
    target = data
}

//将对象写入到json数组中
function saveDataToArray(array,index,data){
    array[index] = data
}

//将对象插入到json数组中
function insertDataToArray(array,index,data){
    array.push(data)
}

//将数组写入到json对象
function saveArrayToData(target,key,array){
    target[key] = array
}

//将数组插入到json对象
function insertArrayToData(target,key,array){
    target[key] = array
}

//将对象写入到本地文件
function saveObjToFile(filepath,fileName,data){
    var str = objToStr(data)
    saveDataToFile(filepath,fileName,str)
}

//将字符串写入到本地文件
function saveDataToFile(filepath,fileName,str){
    if("/" !== filepath.charAt(filepath.length -1)){
        filepath += "/"
    }
    fileIo.source = "file:///" + filepath + fileName
    fileIo.text = str
    fileIo.write()
}

//普通json对象插入到model
function toListModel(json, parent){
    var model = Qt.createQmlObject('import QtQuick 2.2; ListModel{}', parent);
    model.append(json);
    return model;
}

// 用递归输出json text（有问题的，需要优化）
function outputStr(obj){
    var txt = '';
    for (var k in obj){
        if(typeof k === "object") {
            txt += toStr2(obj[x]);
        }
        else{
            txt += k + ":" + obj[x];
        }
        txt += ' ';
    }
    return txt;
}

//json对象创建元素
function creatJsonElement(prop,val){
    if(typeof val === "undefined") {
        delete str1[prop];
    }else {
        // 添加 或 修改
        str1[prop] = val;
    }
}

